﻿using System.Drawing;

namespace Sustainalytics.ReportGenerator.BL
{
    public class ControversiesChartTemplate : Dundas.Charting.WinControl.Chart
    {
        public ControversiesChartTemplate(int width, int height)
        {
            Palette = Dundas.Charting.WinControl.ChartColorPalette.Dundas;
            Size = new Size(width, height);
            BackGradientEndColor = Color.Transparent;
            BorderLineColor = Color.Transparent;
            BorderLineWidth = 0;
            AlwaysRecreateHotregions = true;

            var calibri10RegularFont = new Font("Calibri", 10f, FontStyle.Regular, GraphicsUnit.Point, 1, false);
            
            var defaultChartArea = new Dundas.Charting.WinControl.ChartArea
            {
                BackColor = Color.Transparent,
                BackGradientEndColor = Color.Transparent,
                ShadowColor = Color.Transparent,
                BorderColor = Color.FromArgb(64, 64, 64, 64),
                BorderStyle = Dundas.Charting.WinControl.ChartDashStyle.NotSet,
                Name = "Default",
                AxisY =
                {
                    LineColor = Color.Black,
                    LineWidth = 1,
                    LabelsAutoFit = true,
                    LabelsAutoFitMinFontSize = 10,
                    StartFromZero = true,
                    Minimum = 0,
                    Maximum = 100,
                    MajorGrid =
                    {
                        Interval = 20,
                        LineColor = Color.Black,
                        LineWidth = 1
                    },
                    MajorTickMark =
                    {
                        Enabled = false,
                        Interval = 20,
                        IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.NotSet,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number
                    },
                    LabelStyle =
                    {
                        Enabled = true,
                        Interval = 20,
                        Font = calibri10RegularFont,
                        Format = "P0"
                    }
                },
                AxisX =
                {
                    LineColor = Color.Black,
                    LineWidth = 1,
                    LabelsAutoFit = false,
                    TitleFont = calibri10RegularFont,
                    StartFromZero = false,
                    Minimum = -1,
                    Maximum = 6,
                    MajorGrid =
                    {
                        Enabled = false,
                        Interval = 1,
                        IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.NotSet,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                        LineColor = Color.FromArgb(64, 64, 64, 64)
                    },
                    MajorTickMark =
                    {
                        Enabled = false,
                        Style = Dundas.Charting.WinControl.TickMarkStyle.Inside,
                        Interval = 5,
                        IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number
                    },
                    LabelStyle =
                    {
                        Enabled = true,
                        Font = calibri10RegularFont,
                        FontAngle = -45
                    }
                },
                Position =
                {
                    X = 0, Y = 0, Width = 100, Height = 100, Auto = true
                },
                InnerPlotPosition =
                {
                    Width = 100, Height = 100, Auto = true
                }
            };

            ChartAreas.Add(defaultChartArea);

            var series1Series = new Dundas.Charting.WinControl.Series
            {
                CustomAttributes = "PointWidth=0.5, ColumnLabelStyle=Horizontal, DrawingStyle=Default, LabelStyle=Auto, DrawSideBySide=Auto",
                Name = "Series1",
                Color = Color.Transparent,
                BorderColor = Color.Transparent,
                BorderWidth = 0,
                Font = calibri10RegularFont,
                MarkerStyle = Dundas.Charting.WinControl.MarkerStyle.None,
                MarkerColor = Color.Silver,
                MarkerSize = 10,
                XValueType = Dundas.Charting.WinControl.ChartValueTypes.Int,
                YValueType = Dundas.Charting.WinControl.ChartValueTypes.Int,
                YValuesPerPoint = 2,
                PaletteCustomColors = new Color[] {},
                ShadowOffset = 0,
                ShowLabelAsValue = false,
                ShowInLegend = false,
                LegendText = "Series1"
            };

            Series.Add(series1Series);

            var dataPoint1 = new Dundas.Charting.WinControl.DataPoint
            {
                XValue = 1,
                YValues = new double[] { 0, 0 },
                AxisLabel = "35-40",
                Font = calibri10RegularFont
            };

            series1Series.Points.Add(dataPoint1);
        }
    }
}
